/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package systole.view.crud.tableModels;

import java.util.Date;
import java.util.List;
import systole.domain.analysis.Analysis;
import systole.domain.persons.Medic;
import systole.domain.persons.Patient;
import systole.view.messages.EntityDescriptions;

/**
 *
 * @author jmj
 */
public class AnalysisTableModel extends SystoleTableModel<Analysis> {

    private String[] columnNames = {"Fecha", EntityDescriptions.PATIENT, EntityDescriptions.MEDIC, "Archivo"};
    private static final int DATE_INDEX = 0;
    private static final int PATIENT_INDEX = 1;
    private static final int MEDIC_INDEX = 2;
    private static final int FILE_INDEX = 3;

    public AnalysisTableModel(List<Analysis> entityList) {
        super(entityList);

    }

    public int getColumnCount() {
        return this.columnNames.length;
    }

    public String getColumnName(int arg0) {
        return this.columnNames[arg0];
    }

    public Class<?> getColumnClass(int arg0) {
        switch (arg0) {
            case AnalysisTableModel.DATE_INDEX:
                return Date.class;
            case AnalysisTableModel.PATIENT_INDEX:
                return Patient.class;
            case AnalysisTableModel.MEDIC_INDEX:
                return Medic.class;
            case AnalysisTableModel.FILE_INDEX:
                return String.class;
        }
        return null;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case AnalysisTableModel.DATE_INDEX:
                return this.entities.get(rowIndex).getAnalysisDay();
            case AnalysisTableModel.PATIENT_INDEX:
                return this.entities.get(rowIndex).getPatient();
            case AnalysisTableModel.MEDIC_INDEX:
                return this.entities.get(rowIndex).getMedic();
            case AnalysisTableModel.FILE_INDEX:
                return this.entities.get(rowIndex).getFileName();
        }
        return null;
    }

    public void setValueAt(Object value, int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case AnalysisTableModel.DATE_INDEX:
                this.entities.get(rowIndex).setAnalysisDay((Date) value);
                break;
            case AnalysisTableModel.PATIENT_INDEX:
                this.entities.get(rowIndex).setPatient((Patient) value);
                break;
            case AnalysisTableModel.MEDIC_INDEX:
                this.entities.get(rowIndex).setMedic((Medic) value);
                break;
            case AnalysisTableModel.FILE_INDEX:
                this.entities.get(rowIndex).setFileName((String) value);
                break;
        }
    }
}
